﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ActionServices;
using CoreData;
using Helper;

namespace ZidoniCMS.Areas.Administrator.Controllers
{
    public class OrderServiceManagementController : BaseController
    {
        //
        // GET: /Administrator/OrderService/
        //
        // GET: /Administrator/OrderManagement/
        public OrderServiceManagementController(IOrderServiceActionService orderservice, 
            IUserActionService user)
            : base(orderservice, user)
        {
            try
            {
                if (Permission == null || Permission.Count <= 0)
                {
                    SetPermission(UserID, GroupID, UserName);
                }
                SessionManagement.SetSesionValue("pvalue", Permission.FirstOrDefault(c => c.Module.Equals(Helper.ValueDefine.ORDERSERVICE)).Role);
            }
            catch { }
        }

        #region Main
        /// <summary>
        /// Trang đơn đặt phòng hoặc xe
        /// </summary>
        /// <param name="typeid">Loại đơn là xe hoặc phòng</param>
        /// <returns></returns>
        public ActionResult Index(int typeid=1)
        {
            if (typeid == (int)ValueDefine.OrderServiceType.hotel) {
                ViewBag.TitleName = "Đơn đặt phòng";
            }
            else if (typeid == (int)ValueDefine.OrderServiceType.vehicle)
            {
                ViewBag.TitleName = "Đơn đặt xe";
            }
            ViewBag.TypeID = typeid;
            return SetUpSecurity();
        }
        /// <summary>
        /// Danh sách đơn đặt
        /// </summary>
        /// <param name="status"></param>
        /// <param name="typeid"></param>
        /// <returns></returns>
        public ActionResult _ShowAll(int status, int typeid)
        {
            var data = Order_serviceService.GetByTypeStatus(status, typeid);
            ViewBag.TypeID = typeid;
            return PartialView(data);
        }
        #endregion

        #region CRUD
        /// <summary>
        /// view
        /// </summary>
        /// <returns></returns>
        public ActionResult AddOrUpdate(int id = 0)
        {
            return CanUpdate((int)id);
        }

        public ActionResult _AddOrUpdate(int id)
        {
            var data = Order_serviceService.GetByID(id);
            return PartialView(data);
        }

        /// <summary>
        /// Action
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddOrUpdate(OrderService model, HttpPostedFileBase file)
        {

            var id = this.Order_serviceService.Save(model);

            var data = this.Order_serviceService.GetByID(id);
            return Json(data, JsonRequestBehavior.AllowGet);
        }


        public ActionResult Delete(int id)
        {
            this.Order_serviceService.Delete(this.Order_serviceService.GetByID(id));
            return RedirectToAction("Index", "OrderServiceManagement");
        }


        public ActionResult Details(int id)
        {
            var data = Order_serviceService.GetByID(id);
            return View(data);
        }
        #endregion

    }
}
